package com.hc.java.thread;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/6/8 21:12
 */
public class 停止线程 {
    private static boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            System.out.println("1、标记");
            while (flag) {
                System.out.println(111);
            }
        }, "t1");
        Thread t2 = new Thread(() -> {
            System.out.println("2、中断");
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println(222);
            }
        }, "t2");
        Thread t3 = new Thread(() -> {
            System.out.println("3、stop");
            while (true) {
                System.out.println(333);
            }
        }, "t3");
        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(100);
        flag = false;
        t2.interrupt();
        t3.stop();
    }
}
